using System.Collections;
using UnityEngine;

public class ChangeAlphaOnEnable : MonoBehaviour
{
	public UISprite target;

	public float time;

	private void OnEnable()
	{
		StartCoroutine(Show());
	}

	private void OnDisable()
	{
		StopAllCoroutines();
	}

	private IEnumerator Show()
	{
		float curTime = 0f;
		float alpha = target.color.a;
		Color c = target.color;
		c.a = 0f;
		target.color = c;
		yield return new WaitForSeconds(0.1f);
		for (; curTime < time; curTime += Time.deltaTime)
		{
			c.a = curTime / time * alpha;
			target.color = c;
			yield return null;
		}
	}
}
